package com.demostic.demostic_test.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.demostic.demostic_test.R;
import com.demostic.demostic_test.entity.MapInfo;
import com.demostic.demostic_test.ui.MapManageItemView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class ManageMapAdapter901 extends RecyclerView.Adapter<ManageMapAdapter901.MyViewHolder> {
    public int CREATE = 1;
    public int SAVE = 2;
    private final String TAG = ManageMapAdapter901.class.getSimpleName();
    public int USE_TYPE;
    private Context context;
    private ArrayList<MapInfo> dataList;
    private SimpleDateFormat fmt;
    private OnClickListener mOnClickListener;

    public interface OnClickListener {
        void onDelBtnClick(int i);

        void onUseBtnClick(int i);
    }

    public ManageMapAdapter901(Context context2, ArrayList<MapInfo> dataList2) {
        this.context = context2;
        this.dataList = dataList2;
        init();
    }

    private void init() {
        this.fmt = new SimpleDateFormat(this.context.getString(R.string.dataformat));
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(this.context).inflate(R.layout.map_list_item901, parent, false));
    }

    public void onBindViewHolder(MyViewHolder holder, final int position) {
        MapInfo mapInfo = this.dataList.get(position);
        if (position == 0) {
            boolean isHistoryContains = false;
            holder.map_title.setText(this.context.getString(R.string.cur_map));
            if (this.dataList.size() > 1) {
                for (int i = 1; i < this.dataList.size(); i++) {
                    if (this.dataList.get(i).getStart_time() == this.dataList.get(0).getStart_time()) {
                        isHistoryContains = true;
                    }
                }
            }
            if (isHistoryContains) {
                holder.del_btn.setVisibility(0);
                holder.use_btn.setText(this.context.getString(R.string.not_use_curmap));
                this.USE_TYPE = this.CREATE;
            } else {
                holder.del_btn.setVisibility(8);
                if (mapInfo.getStart_time() == 0) {
                    holder.use_btn.setText(this.context.getString(R.string.not_use_curmap));
                    this.USE_TYPE = this.CREATE;
                } else {
                    holder.use_btn.setText(this.context.getString(R.string.save_cur_map));
                    this.USE_TYPE = this.SAVE;
                }
            }
        } else {
            holder.map_title.setText(this.context.getString(R.string.his_map));
            holder.del_btn.setVisibility(0);
            holder.use_btn.setVisibility(0);
            holder.use_btn.setText(this.context.getString(R.string.use_map));
            holder.del_btn.setText(this.context.getString(R.string.del_map));
            holder.del_btn.setBackgroundResource(R.drawable.corner_tv_901);
            holder.del_btn.setTextColor(this.context.getResources().getColor(R.color.red));
            holder.map_time.setVisibility(0);
        }
        if (mapInfo.getStart_time() == 0) {
            holder.no_map.setVisibility(0);
            holder.map_time.setText((CharSequence) null);
            addMapView(holder, mapInfo);
        } else {
            holder.no_map.setVisibility(8);
            holder.map_time.setText(this.fmt.format(new Date(1000 * mapInfo.getStart_time())));
            addMapView(holder, mapInfo);
        }
        holder.del_btn.setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.adapter.ManageMapAdapter901.AnonymousClass1 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                if (ManageMapAdapter901.this.mOnClickListener != null) {
                    ManageMapAdapter901.this.mOnClickListener.onDelBtnClick(position);
                }
            }
        });
        holder.use_btn.setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.adapter.ManageMapAdapter901.AnonymousClass2 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                if (ManageMapAdapter901.this.mOnClickListener != null) {
                    ManageMapAdapter901.this.mOnClickListener.onUseBtnClick(position);
                }
            }
        });
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.mOnClickListener = onClickListener;
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public int getItemCount() {
        return this.dataList.size();
    }

    /* access modifiers changed from: package-private */
    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView del_btn;
        TextView map_time;
        TextView map_title;
        TextView no_map;
        RelativeLayout rl_map;
        TextView use_btn;

        MyViewHolder(View itemView) {
            super(itemView);
            this.map_title = (TextView) itemView.findViewById(R.id.map_title);
            this.map_time = (TextView) itemView.findViewById(R.id.map_time);
            this.no_map = (TextView) itemView.findViewById(R.id.no_map);
            this.del_btn = (TextView) itemView.findViewById(R.id.del_btn);
            this.use_btn = (TextView) itemView.findViewById(R.id.use_btn);
            this.rl_map = (RelativeLayout) itemView.findViewById(R.id.rl_map);
        }
    }

    private void setCreateNewMapBtn(TextView usetv, TextView deltv) {
        usetv.setVisibility(8);
        deltv.setVisibility(0);
        deltv.setText(this.context.getString(R.string.not_use_curmap));
        deltv.setBackgroundResource(R.drawable.corner_tv_901_);
        deltv.setTextColor(this.context.getResources().getColor(R.color.all_title_color));
    }

    private void addMapView(MyViewHolder holder, MapInfo mapInfo) {
        MapManageItemView cvView = new MapManageItemView(this.context, mapInfo);
        cvView.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        holder.rl_map.addView(cvView);
    }
}
